
window.onload = function() {
    clockStart();
}

function clockStart() {
    var today = new Date()
    var h = today.getHours()
    var m = today.getMinutes()
    var s = today.getSeconds()
    changeTimeType(h,m,s)
    t = setTimeout("clockStart()", 500)
}
function changeImg(){
    var img = document.getElementsByTagName('img')[0];
    console.log(img.src);
    if(img.src.endsWith('head1.png')) img.src = 'head2.png';
    else img.src ='head1.png';
    console.log(img.src);
    alert(document.getElementById('timer_txt').value);
}
function changeTimeType(h, m, s){
    var img = document.getElementsByTagName('img')[0];
    if(img.src.endsWith('head1.png'){
        document.getElementById("txt_clock").innerHTML = changeTime(h, m, s);
    }else document.getElementById("txt_clock").innerHTML = h + ":" + m + ":" + s;
}

function changeTime(h, m, s){
    var temp = 'am';
    if(h < 10) h = '0' + h;
    else if(h > 12){
        h -= 12;
        temp = 'pm'
    } 
    if(m < 10) m = '0' + m;
    if(s < 10) s = '0' + s;   
    return h + ':' + m + ':' + s + ' ' + temp;
}
var counter = 0
function timerStart() {
    document.getElementById("timer_txt").value = counter++;
    const a=setTimeout("timerStart()", 1000);
    if(counter=15){
        var img=document.getElementsByTagName('img')[0];
        var clock=document.getElementById("txt_clock").innerText;
        if(img.src.endsWith('head1.png')){
            alert("男生"+clock);
        }else{
            alert("女生"+clock);
        }
    }
}

function stop() {
    clearTimeout(timerStart);
    document.getElementById("timer_txt").value=0;
    counter=0;
}
function pause(){
    clearTimeout(a);
}